home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Sample Extensions / Bell Test ƒ / MenuSelect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  3.8 KB  |  166 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         MenuSelect.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a CODE resource to be installed as a Trap Patch.
  9.  
  10.     NOTES:
  11.         •    Causes the Mac to beep when About... is selected from the Apple
  12.             menu.
  13.  
  14.     ___________________________________________________________________________
  15.  
  16.     VERSION HISTORY:
  17.         (Jan 1994, dg)
  18.             •    First publicly distributed version.
  19.  
  20.         (Mar 1994, dg)
  21.             •    Extended address table, uses code block to play sound.
  22.  
  23.  
  24.     ___________________________________________________________________________
  25. */
  26. //=============================================================================
  27. //        Include files                                                                     
  28. //-----------------------------------------------------------------------------
  29. #include <GestaltEqu.h>
  30. #include "StandaloneCode.h"
  31. #include "BTAddrsTable.h"
  32. #include "ESConstants.h"
  33. #include "CodeConstants.h"
  34.  
  35.  
  36.  
  37.  
  38.  
  39. //=============================================================================
  40. //        Private defines                                                                 
  41. //-----------------------------------------------------------------------------
  42. #define AppleSymbol                0xF0                // The Apple symbol
  43.  
  44.  
  45.  
  46.  
  47.  
  48. //=============================================================================
  49. //        Global Variables                                                                 
  50. //-----------------------------------------------------------------------------
  51. pascal long    (*gPrevMenuSelect) (Point pt);
  52. pascal void    (*gPlaySound) (void);
  53. Boolean        gAlreadyRan=false;
  54.  
  55.  
  56.  
  57.  
  58.  
  59. //=============================================================================
  60. //        Private function prototypes                             
  61. //-----------------------------------------------------------------------------
  62. pascal    long main(Point pt);
  63. short    IsAppleMenu(MenuHandle menuH);
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. //=============================================================================
  75. //        main : Entry point to our code resource.                                                                 
  76. //-----------------------------------------------------------------------------
  77. //        Note :    We call the original MenuSelect, then do some post processing.
  78. //                The net effect is to make the Mac beep when you select
  79. //                About.. from the Apple menu.
  80. //-----------------------------------------------------------------------------
  81. pascal long main(Point pt)
  82. {    long            retVal;                    // Long returned with menu id and item number
  83.     MenuHandle        menuH;
  84.     short            menuIDNum;
  85.     BTAddressTable    *theAddressTable;
  86.     
  87.  
  88.  
  89.  
  90.     // Get access to our globals, and save off A4
  91.     PatchGetGlobals();
  92.  
  93.     
  94.     
  95.     // If we've not already been called, call the Gestalt selector to get
  96.     // the address of the old MenuSelect and the routine to play the
  97.     // sound. Cast the table entry to a long first so we get what's pointed
  98.     // to by it, rather than a pointer to it.
  99.     if (!gAlreadyRan)
  100.         {
  101.         Gestalt(kBellTestAddressTable, &theAddressTable);        
  102.         gPrevMenuSelect    = (ProcPtr) ((long) theAddressTable->theTable[kMenuSelect]);
  103.         gPlaySound        = (ProcPtr) ((long) theAddressTable->theTable[kPlaySound]);
  104.         gAlreadyRan        = true;
  105.         }
  106.  
  107.     
  108.     
  109.     // Call the original MenuSelect()
  110.     retVal = (*gPrevMenuSelect)(pt);
  111.  
  112.  
  113.     
  114.     // If the user made a choice (menu ID != 0)
  115.     if (menuIDNum = HiWord(retVal))
  116.         {
  117.         // Get a handle to the menu.
  118.         menuH = GetMHandle(menuIDNum);
  119.         
  120.     
  121.         
  122.         // If it's the Apple menu, and it's the first item,
  123.         // then call our block to play the sound.
  124.         if (IsAppleMenu(menuH) && (LoWord(retVal) == 1))
  125.             (*gPlaySound)();
  126.         }
  127.     
  128.     
  129.  
  130.     // Restore A4 for our caller and return
  131.     PatchUngetGlobals();
  132.     return(retVal);
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. //=============================================================================
  145. //        IsAppleMenu : Is a given menu the Apple menu?
  146. //-----------------------------------------------------------------------------
  147. short IsAppleMenu(MenuHandle menuH)
  148. {    
  149.  
  150.  
  151.  
  152.  
  153.     // Quick check
  154.     if (!menuH)
  155.         return(false);
  156.     
  157.     
  158.     
  159.     // Real check
  160.     if (((*menuH)->menuData[0] == 1) &&
  161.             (((*menuH)->menuData[1] == 0x14) || ((*menuH)->menuData[1] == AppleSymbol)))
  162.         return(true);
  163.     else
  164.         return(false);
  165. }
  166.